self.addEventListener('install', function (event) {
    event.waitUntil(
        console.log("servicework安装成功")
    );
})
console.log(self)

let proxyOrgin = self.location.origin;
let realOrgin;

addEventListener('fetch', e => {
    console.log(e)
    let responsePromise = fetchHandler(e);
    let b = e.request.url.indexOf('bundle.js') > -1;
    if (b) {
        e.respondWith(responsePromise);
    }
})


function makeHtmlRes(body, status = 200) {
    return new Response(body, {
        status,
        headers: {
            'content-type': 'application/javascript; charset=utf-8',
        }
    })
}


async function fetchHandler(e) {
    const res = await fetch('http://localhost:8888/install.js');
    return makeHtmlRes(res.body);
}


